'use strict';

module.exports = app => {
    const { Sequelize, model } = app

    const Model = model.define('minaOrder', {
        id:{
            type: Sequelize.STRING.BINARY,
            defaultValue: Sequelize.UUIDV1,
            primaryKey: true
        },
        corpName: {
            type: Sequelize.STRING(30),
        },
        minaCouponQuota: {
            type: Sequelize.INTEGER(6),
        },
        carType: {
            type: Sequelize.INTEGER(1),
            allowNull: false,
        },
        delivery: {
            type: Sequelize.INTEGER(1),
            allowNull: false,
        },
        allopatry: {
            type: Sequelize.BOOLEAN,
            allowNull: false,
        },
        price: {
            type: Sequelize.INTEGER,
            allowNull: false,
        },
        userName: {
            type: Sequelize.STRING(20),
            allowNull: false,
        },
        userPhone: {
            type: Sequelize.STRING(20),
            allowNull: false,
        },
        carNum: {
            type: Sequelize.STRING(10),
            allowNull: false,
        },
        bookAt: {
            type: Sequelize.STRING(20),
            allowNull: false,
        },
        bookTimeSlot: {
            type: Sequelize.STRING(2),
            allowNull: false,
        },
        registerAt: {
            type: Sequelize.STRING(20),
            allowNull: false,
        },
        pickUpPlace: {
            type: Sequelize.STRING(100),
        },
        area: {
            type: Sequelize.STRING(10),
        },
        returnPlace: {
            type: Sequelize.STRING(100),
        },
        remark: {
            type: Sequelize.STRING(50),
        },
        formId: {
            type: Sequelize.STRING(50),
        },
        prepayId: {
            type: Sequelize.STRING(50),
        },
        status: {
            type: Sequelize.INTEGER(8),
            defaultValue: 0,
            allowNull: false,
        },
    }, {
        freezeTableName: true,
        tableName: 'mina_order',
        timestamps: true,
        paranoid: true,
    })

    Model.associate = function() {
        model.MinaOrder.belongsTo(model.Corp)
        model.MinaOrder.belongsTo(model.MinaUser)
        model.MinaOrder.belongsTo(model.MinaPartner)
        model.MinaOrder.belongsTo(model.MinaUserCoupon)
        model.MinaOrder.belongsTo(model.MinaCity)

        model.Corp.hasMany(model.MinaOrder)
        model.MinaUser.hasMany(model.MinaOrder)
        model.MinaPartner.hasMany(model.MinaOrder)
        model.MinaUserCoupon.hasOne(model.MinaOrder)
        model.MinaCity.hasMany(model.MinaOrder)
    }

    return Model
}